package com.lenovo.smarttraffic.database.dao;

import android.content.Context;

/**
 * author  张猛
 **/
public class DaoManager_Need {
    private Context mContext;
    private static final String DB_NAME = "need_title.db";
    private volatile static DaoManager_Need mInstance_Need;
    private static DaoMaster mDaoMaster_Need;
    private static DaoMaster.DevOpenHelper mHelper_Need;
    private static DaoSession mDaoSession_Need;

    public DaoManager_Need() {
    }

    public static DaoManager_Need getmInstance_Need() {
        if (mInstance_Need == null) {
            synchronized (DaoManager_Need.class) {
                if (mInstance_Need == null) {
                    mInstance_Need = new DaoManager_Need();
                }
            }
        }
        return mInstance_Need;
    }



    public void init(Context context) {
        this.mContext = context;
    }

    public DaoMaster getDaoManager_Need() {
        if (mDaoMaster_Need == null) {
            mHelper_Need = new DaoMaster.DevOpenHelper(mContext, DB_NAME, null);
            mDaoMaster_Need = new DaoMaster(mHelper_Need.getWritableDatabase());
        }
        return mDaoMaster_Need;
    }

    public DaoSession getDaoSession_Need() {
        if (mDaoSession_Need == null) {
            if (mDaoMaster_Need == null) {
                mDaoMaster_Need = getDaoManager_Need();
            }
            mDaoSession_Need = mDaoMaster_Need.newSession();
        }
        return mDaoSession_Need;
    }

    public void closeConnection() {
        closeHelper();
        closeDaoSession();
    }

    public void closeHelper() {
        if (mHelper_Need != null) {
            mHelper_Need.close();
            mHelper_Need = null;
        }
    }

    public void closeDaoSession() {
        if (mDaoSession_Need != null) {
            mDaoSession_Need.clear();
            mDaoSession_Need = null;
        }
    }

}
